﻿using System;
using System.Data;
using System.Configuration;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Runtime.Serialization;
using System.Collections.Generic;
/// <summary>
///table 的摘要说明
/// </summary>
[Serializable]
public class table
{
	public table()
	{
		//
		//TODO: 在此处添加构造函数逻辑
		//
	}

    private string id;
    private string name;
    private string headColor;
    private List<row> m_rows;
    private string filename;

    public string Id
    {
        get
        {
            return id;
        }
        set
        {
            id = value;
        }
    }

    public string Name
    {
        get
        {
            return name;
        }
        set
        {
            name = value;
        }
    }

    public string HeadColor
    {
        get;
        set;
    }
    public List<row> Mrows
    {
        get
        {
            return m_rows;
        }
        set
        {
            m_rows = value;
        }
    }

    public row this[int i]
    {
        get
        {
            return this.m_rows[i];
        }
        set
        {
            this.m_rows[i] = value;
        }
    }

    public row getRowByID(string id)
    {
        foreach (row el in m_rows)
        {
            if (el.Id.ToString() == id)
            {
                return el;
            } 
        }
        return null;
    }

    public bool swapRowByID(string idA, string idB)
    {
        int indexA = -1, indexB = -1;
        for (int i = 0; i < m_rows.Count; i++)
        {
            if (m_rows[i].Id.ToString() == idA || m_rows[i].Id.ToString() == idB)
            {
                if (indexA == -1)
                {
                    indexA = i;
                }
                else if (indexB == -1)
                {
                    indexB = i;
                    break; ;
                }
            }
        }

        row tmpRow = m_rows[indexA];
        m_rows[indexA] = m_rows[indexB];
        m_rows[indexB] = tmpRow;

        return true;
    }

    public table(string _id, string _name,string _void)
    {
        this.id = _id;
        this.name = _name;
    }
}